@Echo off
Echo --------------------------------------------------------------------------------
Echo %~f0 %*

:: File: C:\Documents and Settings\paul\My Documents\Src\Batch\set_GRAILS.cmd
:: Date: 10:56 PM 12/19/2010

:: Requires the current environment to have DelayedExpansion and 
:: CommandExtensions enabled for Current User {HKCU} or Local Machine {HKLM}:
::    reg add "HKCU\Software\Microsoft\Command Processor" /V EnableExtensions  /T REG_DWORD  /d 0x1 /f
::    reg add "HKCU\Software\Microsoft\Command Processor" /V DelayedExpansion  /T REG_DWORD  /d 0x1 /f
    
Set GRAILS_HOME=
Set GRAILSCMD=

If /I "%1" equ "latest"  "%~0" 136
Call :ChkGrails "%~1" grails-1.3.6 1.3.6 136  grails-1.2.5 1.2.5 125  grails-1.1.2 1.1.2 112

Exit /B

:: ----------------------------------------------------------------------------
:: ----------------------------------------------------------------------------

:: ChkGrails Params:
::    User-supplied cmd line parm, 
::    triplets of directory/version tags.
::       The first tag of the triplet must be the actual directory name
::       The second and third tags are aliases

:ChkGrails
Set PARMS=

:ChkGrailsLoop
Set PARMS=!PARMS! %2 or %3 or %4 ;
If /I "%~1" equ "%~2" Set GRAILS_HOME=c:\Program Files\grails.org\%~2
If /I "%~1" equ "%~3" Set GRAILS_HOME=c:\Program Files\grails.org\%~2
If /I "%~1" equ "%~4" Set GRAILS_HOME=c:\Program Files\grails.org\%~2
:: If first tag of next triplet is blank, we are done.
:: If we found a HOME, set stuff dependent on HOME.
If "%~5"=="" (
   If "!GRAILS_HOME!"=="" (
      Echo.
      Echo Looking for a valid Grails version:
      Echo !PARMS!
   ) Else (
      Set GRAILSCMD=!GRAILS_HOME!\bin\groovy.exe
      Echo GRAILS_HOME=!GRAILS_HOME!
      Echo GRAILSCMD=!GRAILSCMD!
      "!GRAILSCMD!" --version
   )
   Exit /B
)
:: Keep %1, scroll next triplet into %2 %3 %4
Shift /2
Shift /2
Shift /2 
Goto :ChkGrailsLoop

